const Service = require('egg').Service;

class GroupService extends Service {
	async getGroup() {
		const {
			app,
			ctx
		} = this;
		const {
			keyword,
			pid
		} = ctx.query;
		let provinces = []
		let sql = `select * from groups where 1=1 `
		if (keyword) {
			sql += `and title like "%${keyword}%" `
		}
		if (pid) {
			let proSql = `select * from city where pid=${pid}`
			provinces = await app.mysql.query(proSql)
		}
		const data = await app.mysql.query(sql)
		return {data,provinces}
	}
	async delGroup() {
		const {
			ctx,
			app
		} = this;
		const data = await app.mysql.delete('groups', {
			id: ctx.params.id
		}); // 根据id删除
		return data
	}
}

module.exports = GroupService;